package com.liu.stockmarket.ui.statistics.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.liu.stockmarket.R
import com.liu.stockmarket.model.Stock
import com.liu.stockmarket.utils.getString
import com.liu.stockmarket.utils.money
import java.math.BigDecimal

class HistoryAdapter : BaseQuickAdapter<HistoryAdapter.Item, BaseViewHolder>(
    R.layout.item_history
), LoadMoreModule {


    override fun convert(holder: BaseViewHolder, item: Item) {
        holder.setText(R.id.tv_name, item.name)
            .setText(R.id.tv_code, item.code)
            .setText(R.id.tv_type, item.type.text)
            .setBackgroundColor(R.id.tv_type,when(item.type){
                Stock.StockType.STOCK->context.getColor(R.color.line_stock)
                Stock.StockType.BOND->context.getColor(R.color.line_bond)
                Stock.StockType.FUND->context.getColor(R.color.line_fund)
                else->context.getColor(R.color.color_primary)
            })
            .setText(R.id.tv_holding_day, "${item.holdingDay}天")
            .setText(R.id.tv_transaction_count, "${item.transactionCount}")
            .setText(R.id.tv_handling_fee, item.handlingFee.getString())

        holder.getView<TextView>(R.id.tv_profit).money(this.context, item.totalProfit)

    }

    data class Item(
        val stockId: Long,
        val name: String,
        val code: String,
        val holdingDay: Long,
        val totalProfit: BigDecimal,
        val todayProfit:BigDecimal,
        val type: Stock.StockType,
        val transactionCount: Int,
        val handlingFee: BigDecimal
    )
}